package com.probiz.estoremf.sales.web.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.ArrayUtils;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.sales.PromoRule;
import com.probiz.estore.core.controller.GenericStoreFrontController;
import com.probiz.estore.sales.service.PromoRuleManager;

public class PromoRuleListFrontController extends GenericStoreFrontController<PromoRule> {
	private PromoRuleManager promoRuleManager;
	public void setPromoRuleManager(PromoRuleManager promoRuleManager) {
		this.promoRuleManager = promoRuleManager;
	}
	protected void initController() throws Exception {
		mgr = promoRuleManager; 
		
	}
	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("sales/defaultPromoRuleList");
		
		List<PromoRule> promoRuleListInProcess = promoRuleManager.getAllPromotionRulesInProcessForFront();
		List<PromoRule> promoRuleListInFuture = promoRuleManager.getAllPromotionRulesInFutureForFront();
		
		List<PromoRule> promoRuleList = new ArrayList<PromoRule>();
		promoRuleList.addAll(promoRuleListInProcess);
		promoRuleList.addAll(promoRuleListInFuture);
		
		mv.addObject("promoRuleList", promoRuleList);
		
		// ------start:把页面字体大小设置到attribute中------
		Cookie[] cookies = request.getCookies();
		if (!ArrayUtils.isEmpty(cookies)) {
			for (Cookie cookie : cookies) {
				if (cookie.getName().equals("listFontSize")) {
					mv.addObject("listFontSize", cookie.getValue());
				}
			}
		}
		// ------end:把页面字体大小设置到attribute中------
		return mv;
	}
	

}
